/**
 * created by 小卷毛, 2021-07-21
 * Copyright (c) 2021, 416143467@qq.com All Rights Reserved.
 * #                   *********                            #
 * #                  ************                          #
 * #                  *************                         #
 * #                 **  ***********                        #
 * #                ***  ****** *****                       #
 * #                *** *******   ****                      #
 * #               ***  ********** ****                     #
 * #              ****  *********** ****                    #
 * #            *****   ***********  *****                  #
 * #           ******   *** ********   *****                #
 * #           *****   ***   ********   ******              #
 * #          ******   ***  ***********   ******            #
 * #         ******   **** **************  ******           #
 * #        *******  ********************* *******          #
 * #        *******  ******************************         #
 * #       *******  ****** ***************** *******        #
 * #       *******  ****** ****** *********   ******        #
 * #       *******    **  ******   ******     ******        #
 * #       *******        ******    *****     *****         #
 * #        ******        *****     *****     ****          #
 * #         *****        ****      *****     ***           #
 * #          *****       ***        ***      *             #
 * #            **       ****        ****                   #
 */
package com.rzico.sbl.viewmodel

import androidx.lifecycle.MutableLiveData
import com.lzg.extend.BaseResponse
import com.lzg.extend.JsonConvert
import com.lzg.extend.jackson.JacksonConvert
import com.lzg.okrx.adapter.FlowableBody
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.HttpMethod
import com.rzico.sbl.model.*
import com.xinnuo.common.helper.getTimeString
import com.xinnuo.common_ui.base.addItems
import com.xinnuo.common_ui.utils.applyFlowableSchedulers
import com.xinnuo.common_ui.utils.subscribeByFinally

/**
 * 描 述：常用功能统计操作相关
 * 作 者：小卷毛  2021-07-21 16:32
 * 修改描述：
 * 修 改 人：
 * 修改版本：
 */
class StatisticCommonViewModel : DialogViewModel() {

    val mPayEvent = MutableLiveData<ArrayList<CommonData>>()
    val mRecordEvent = MutableLiveData("{}")
    val mBackEvent = MutableLiveData("{}")
    val mBucketTotalEvent = MutableLiveData("{}")

    val mBucketTypeList by lazy {
        listOf(
            FilterData("全部", "", "操作类型", true),
            FilterData("押桶", "mortgage", "押桶"),
            FilterData("借桶", "borrow", "借桶")
        )
    }

    val mBarrelList by lazy {
        listOf(
            FilterData("全部", "", "押桶统计", true),
            FilterData("空桶购买", "barrel", "空桶购买"),
            FilterData("订单买桶", "order", "订单买桶"),
            FilterData("商品买桶", "product", "商品买桶"),
            FilterData("人工押桶", "mortgage", "人工押桶")
        )
    }

    val mTicketUsedList by lazy {
        listOf(
            FilterData("全部", "", "使用类型", true),
            FilterData("订单", "order", "订单"),
            FilterData("核销", "writeOff", "核销")
        )
    }

    /**
     * 押桶统计列表
     */
    fun handleList(
        page: Int,
        keyWord: String,
        type: String,
        beginDate: String,
        endDate: String,
        onSuccess: (ResponseModel<BarrelHandleData>) -> Unit = {},
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.post<BaseResponse<ResponseModel<BarrelHandleData>>>(BaseUrl.stsHandle)
            .isMultipart(true)
            .params(
                getParams(
                    "method" to type,
                    "searchValue" to keyWord,
                    "beginDate" to beginDate,
                    "endDate" to endDate,
                    "pageStart" to page * 20,
                    "pageSize" to 20
                )
            )
            .converter(object : JsonConvert<BaseResponse<ResponseModel<BarrelHandleData>>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data }
            .subscribeByFinally(
                event = this,
                onSuccess = onSuccess,
                onFinally = onFinally
            )
    )

    /**
     * 押桶统计二级列表
     */
    fun handleRecord(
        page: Int,
        keyWord: String,
        barrelId: String,
        method: String,
        beginDate: String,
        endDate: String,
        onSuccess: (ArrayList<HandleData>) -> Unit = {},
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.post<BaseResponse<ResponseModel<HandleData>>>(BaseUrl.mngBucket)
            .isMultipart(true)
            .params(
                getParams(
                    "searchValue" to keyWord,
                    "barrelId" to barrelId,
                    "method" to method,
                    "beginDate" to beginDate,
                    "endDate" to endDate,
                    "pageStart" to page * 20,
                    "pageSize" to 20
                )
            )
            .converter(object : JsonConvert<BaseResponse<ResponseModel<HandleData>>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data.data }
            .subscribeByFinally(
                event = this,
                onSuccess = onSuccess,
                onFinally = onFinally
            )
    )

    /**
     * 押桶统计二级合计
     */
    fun recordTotal(
        keyWord: String,
        barrelId: String,
        method: String,
        beginDate: String,
        endDate: String
    ) =
        request(
            isLoadingBefore = false,
            isLoadingAfter = false,
            requestUrl = BaseUrl.mngBucketSum,
            isMultipart = true,
            params = arrayOf(
                "searchValue" to keyWord,
                "barrelId" to barrelId,
                "method" to method,
                "beginDate" to beginDate,
                "endDate" to endDate
            ),
            onSuccess = { mRecordEvent.value = it }
        )

    /**
     * 退桶桶统计列表
     */
    fun backList(
        page: Int,
        keyWord: String,
        beginDate: String,
        endDate: String,
        onSuccess: (ResponseModel<BarrelHandleData>) -> Unit = {},
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.post<BaseResponse<ResponseModel<BarrelHandleData>>>(BaseUrl.stsBack)
            .isMultipart(true)
            .params(
                getParams(
                    "searchValue" to keyWord,
                    "beginDate" to beginDate,
                    "endDate" to endDate,
                    "pageStart" to page * 20,
                    "pageSize" to 20
                )
            )
            .converter(object : JsonConvert<BaseResponse<ResponseModel<BarrelHandleData>>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data }
            .subscribeByFinally(
                event = this,
                onSuccess = onSuccess,
                onFinally = onFinally
            )
    )

    /**
     * 退桶统计二级列表
     */
    fun backRecord(
        page: Int,
        keyWord: String,
        barrelId: String,
        beginDate: String,
        endDate: String,
        onSuccess: (ArrayList<HandleData>) -> Unit = {},
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.post<BaseResponse<ResponseModel<HandleData>>>(BaseUrl.stsBackDet)
            .isMultipart(true)
            .params(
                getParams(
                    "searchValue" to keyWord,
                    "barrelId" to barrelId,
                    "beginDate" to beginDate,
                    "endDate" to endDate,
                    "pageStart" to page * 20,
                    "pageSize" to 20
                )
            )
            .converter(object : JsonConvert<BaseResponse<ResponseModel<HandleData>>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data.data }
            .subscribeByFinally(
                event = this,
                onSuccess = onSuccess,
                onFinally = onFinally
            )
    )

    /**
     * 退桶统计二级合计
     */
    fun backTotal(
        keyWord: String,
        barrelId: String,
        beginDate: String,
        endDate: String
    ) =
        request(
            isLoadingBefore = false,
            isLoadingAfter = false,
            requestUrl = BaseUrl.stsBackNum,
            isMultipart = true,
            params = arrayOf(
                "searchValue" to keyWord,
                "barrelId" to barrelId,
                "beginDate" to beginDate,
                "endDate" to endDate
            ),
            onSuccess = { mBackEvent.value = it }
        )

    /**
     * 空桶列表
     */
    fun bucketList(
        page: Int,
        keyWord: String,
        type: String,
        barrelId: String,
        onSuccess: (ArrayList<BucketData>) -> Unit = {},
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.post<BaseResponse<ResponseModel<BucketData>>>(BaseUrl.stsBucketSum)
            .isMultipart(true)
            .params(
                getParams(
                    "type" to type,
                    "searchValue" to keyWord,
                    "barrelId" to barrelId,
                    "pageStart" to page * 20,
                    "pageSize" to 20
                )
            )
            .converter(object : JsonConvert<BaseResponse<ResponseModel<BucketData>>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data.data }
            .subscribeByFinally(
                event = this,
                onSuccess = onSuccess,
                onFinally = onFinally
            )
    )

    /**
     * 空桶统计合计
     */
    fun bucketTotal(
        keyWord: String,
        type: String,
        barrelId: String,
    ) =
        request(
            isLoadingBefore = false,
            isLoadingAfter = false,
            requestUrl = BaseUrl.stsBucketTot,
            isMultipart = true,
            params = arrayOf(
                "searchValue" to keyWord,
                "type" to type,
                "barrelId" to barrelId
            ),
            onSuccess = { mBucketTotalEvent.value = it }
        )


    /**
     * 推广员列表
     */
    fun shareList(
        page: Int,
        beginDate: String,
        endDate: String,
        onSuccess: (ArrayList<ShareWorkerData>) -> Unit = {},
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.get<BaseResponse<ResponseModel<ShareWorkerData>>>(BaseUrl.stsShareSum)
            .params(
                getParams(
                    "beginDate" to beginDate,
                    "endDate" to endDate,
                    "pageStart" to page * 20,
                    "pageSize" to 20
                )
            )
            .converter(object : JsonConvert<BaseResponse<ResponseModel<ShareWorkerData>>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data.data }
            .subscribeByFinally(
                event = this,
                onSuccess = onSuccess,
                onFinally = onFinally
            )
    )

    /**
     * 推广记录
     */
    fun shareDetail(
        page: Int,
        adminId: String,
        beginDate: String,
        endDate: String,
        onSuccess: (ArrayList<MemberData>) -> Unit = {},
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.get<BaseResponse<ResponseModel<MemberData>>>(BaseUrl.stsShareDet)
            .params(
                getParams(
                    "id" to adminId,
                    "beginDate" to beginDate,
                    "endDate" to endDate,
                    "pageStart" to page * 20,
                    "pageSize" to 20
                )
            )
            .converter(object : JsonConvert<BaseResponse<ResponseModel<MemberData>>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data.data }
            .subscribeByFinally(
                event = this,
                onSuccess = onSuccess,
                onFinally = onFinally
            )
    )

    /**
     * 推广订单
     */
    fun shareOrders(
        page: Int,
        adminId: String,
        beginDate: String,
        endDate: String,
        onSuccess: (ArrayList<Any>) -> Unit = {},
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.get<BaseResponse<OrderModel>>(BaseUrl.stsShareOrd)
            .params(
                getParams(
                    "promoterId" to adminId,
                    "beginDate" to beginDate,
                    "endDate" to endDate,
                    "pageStart" to page * 20,
                    "pageSize" to 20
                )
            )
            .converter(object : JacksonConvert<BaseResponse<OrderModel>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map {
                ArrayList<Any>().apply {
                    it.data.data.forEachIndexed { index, item ->
                        // 添加头部
                        add(OrderHeader().apply {
                            position = index
                            orderSN = item.sn
                            shippingSn = item.shippingSn.orEmpty()
                            status_hint = item.statusDescr
                            hint = "下单时间："
                            time = item.createDate.getTimeString()
                        })

                        // 添加商品
                        addItems(
                            item.orderItems.onEach {
                                it.orderSN = item.sn
                                it.shippingSn = item.shippingSn.orEmpty()
                                it.position = index
                                it.hopeDate = item.hopeDate.orEmpty()
                                it.fast = item.isFast
                                it.first = item.isFisrst
                            }
                        )

                        // 添加底部
                        add(OrderFooter().apply {
                            position = index
                            orderSN = item.sn
                            shippingSn = item.shippingSn.orEmpty()
                            status = item.status.orEmpty()
                            total_num = item.quantity
                            amount = item.amountPaid.orEmpty()
                            amountHint = "实付款: "
                            name = item.consignee.orEmpty()
                            phone = item.phone.orEmpty()
                            address = item.address
                            memo = item.memo.orEmpty()
                            adminName = item.adminName.orEmpty()
                            createDate = item.createDate.getTimeString()
                            hopeDate = item.hopeDate.getTimeString()
                        })
                    }
                }
            }
            .subscribeByFinally(
                event = this,
                onSuccess = onSuccess,
                onFinally = onFinally
            )
    )

    /**
     * 推广数量
     */
    fun shareCount(
        page: Int,
        adminId: String,
        beginDate: String,
        endDate: String,
        onSuccess: (ResponseModel<HomeContent>) -> Unit = {},
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.get<BaseResponse<ResponseModel<HomeContent>>>(BaseUrl.stsShareNum)
            .params(
                getParams(
                    "promoterId" to adminId,
                    "beginDate" to beginDate,
                    "endDate" to endDate,
                    "pageStart" to page * 20,
                    "pageSize" to 20
                )
            )
            .converter(object : JsonConvert<BaseResponse<ResponseModel<HomeContent>>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data }
            .subscribeByFinally(
                event = this,
                onSuccess = onSuccess,
                onFinally = onFinally
            )
    )

    /**
     * 记账列表
     */
    fun billList(
        page: Int,
        keyWord: String,
        onSuccess: (ResponseModel<BillWorkerData>) -> Unit = {},
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.post<BaseResponse<ResponseModel<BillWorkerData>>>(BaseUrl.stsBillSum)
            .isMultipart(true)
            .params(
                getParams(
                    "searchValue" to keyWord,
                    "pageStart" to page * 20,
                    "pageSize" to 20
                )
            )
            .converter(object : JsonConvert<BaseResponse<ResponseModel<BillWorkerData>>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data }
            .subscribeByFinally(
                event = this,
                onSuccess = onSuccess,
                onFinally = onFinally
            )
    )

    /**
     * 记账还款列表
     */
    fun billPayList(
        page: Int,
        member: String,
        onSuccess: (BillSummary) -> Unit = {},
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.get<BaseResponse<BillSummary>>(BaseUrl.stsBillList)
            .params(
                getParams(
                    "id" to member,
                    "pageStart" to page * 20,
                    "pageSize" to 20
                )
            )
            .converter(object : JacksonConvert<BaseResponse<BillSummary>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data }
            .subscribeByFinally(
                event = this,
                onSuccess = onSuccess,
                onFinally = onFinally
            )
    )

    /**
     * 记账订单
     */
    fun billOrder(
        page: Int,
        member: String,
        beginDate: String,
        endDate: String,
        onSuccess: (ArrayList<OrderData>) -> Unit = {},
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.get<BaseResponse<OrderModel>>(BaseUrl.stsOrderDet)
            .params(
                getParams(
                    "memberId" to member,
                    "beginDate" to beginDate,
                    "endDate" to endDate,
                    "paymentPluginId" to "monthPayPlugin",
                    "pageStart" to page * 20,
                    "pageSize" to 20
                )
            )
            .converter(object : JacksonConvert<BaseResponse<OrderModel>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data.data }
            .subscribeByFinally(
                event = this,
                onSuccess = onSuccess,
                onFinally = onFinally
            )
    )

    /**
     * 送货统计一级列表
     */
    fun shipList(
        page: Int,
        beginDate: String,
        endDate: String,
        onSuccess: (ResponseModel<SendWorkerData>) -> Unit = {},
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.get<BaseResponse<ResponseModel<SendWorkerData>>>(BaseUrl.stsShipSum)
            .params(
                getParams(
                    "beginDate" to beginDate,
                    "endDate" to endDate,
                    "pageStart" to page * 20,
                    "pageSize" to 20
                )
            )
            .converter(object : JsonConvert<BaseResponse<ResponseModel<SendWorkerData>>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data }
            .subscribeByFinally(
                event = this,
                onSuccess = onSuccess,
                onFinally = onFinally
            )
    )

    /**
     * 送货商品列表
     */
    fun shipGoods(
        page: Int,
        adminId: String,
        beginDate: String,
        endDate: String,
        onSuccess: (ResponseModel<HomeContent>) -> Unit = {},
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.get<BaseResponse<ResponseModel<HomeContent>>>(BaseUrl.stsShipGod)
            .params(
                getParams(
                    "adminId" to adminId,
                    "beginDate" to beginDate,
                    "endDate" to endDate,
                    "pageStart" to page * 30,
                    "pageSize" to 30
                )
            )
            .converter(object : JsonConvert<BaseResponse<ResponseModel<HomeContent>>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data }
            .subscribeByFinally(
                event = this,
                onSuccess = onSuccess,
                onFinally = onFinally
            )
    )

    /**
     * 付款方式
     */
    fun getPayment() =
        requestCommon(
            isLoading = true,
            requestUrl = BaseUrl.manuWay,
            requestMethod = HttpMethod.GET,
            onSuccess = { mPayEvent.value = it }
        )

    /**
     * 送货订单记录列表
     */
    fun shipDetail(
        page: Int,
        adminId: String,
        orderMethod: String,
        payMethod: String,
        beginDate: String,
        endDate: String,
        onSuccess: (ArrayList<OrderData>) -> Unit = {},
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.get<BaseResponse<OrderModel>>(BaseUrl.stsShipDet)
            .params(
                getParams(
                    "adminId" to adminId,
                    "orderMethod" to orderMethod,
                    "payMethod" to payMethod,
                    "beginDate" to beginDate,
                    "endDate" to endDate,
                    "pageStart" to page * 20,
                    "pageSize" to 20
                )
            )
            .converter(object : JacksonConvert<BaseResponse<OrderModel>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data.data }
            .subscribeByFinally(
                event = this,
                onSuccess = onSuccess,
                onFinally = onFinally
            )
    )

    /**
     * 水票统计一级列表
     */
    fun ticketList(
        page: Int,
        keyWord: String,
        beginDate: String,
        endDate: String,
        onSuccess: (ResponseModel<TicketBarrelData>) -> Unit = {},
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.post<BaseResponse<ResponseModel<TicketBarrelData>>>(BaseUrl.stsTicketSum)
            .isMultipart(true)
            .params(
                getParams(
                    "searchValue" to keyWord,
                    "beginDate" to beginDate,
                    "endDate" to endDate,
                    "pageStart" to page * 20,
                    "pageSize" to 20
                )
            )
            .converter(object : JsonConvert<BaseResponse<ResponseModel<TicketBarrelData>>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data }
            .subscribeByFinally(
                event = this,
                onSuccess = onSuccess,
                onFinally = onFinally
            )
    )

    /**
     * 水票剩余明细列表
     */
    fun ticketDetail(
        page: Int,
        goodsId: String,
        keyWord: String,
        onSuccess: (ArrayList<TicketBarrelData>) -> Unit = {},
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.get<BaseResponse<ResponseModel<TicketBarrelData>>>(BaseUrl.stsTicketDet)
            .params(
                getParams(
                    "type" to "water",
                    "searchValue" to keyWord,
                    "goodsId" to goodsId,
                    "pageStart" to page * 20,
                    "pageSize" to 20
                )
            )
            .converter(object : JsonConvert<BaseResponse<ResponseModel<TicketBarrelData>>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data.data }
            .subscribeByFinally(
                event = this,
                onSuccess = onSuccess,
                onFinally = onFinally
            )
    )

    /**
     * 水票使用、赠送、售卖记录
     */
    fun ticketChange(
        page: Int,
        type: String,
        goodsId: String,
        method: String,
        beginDate: String,
        endDate: String,
        onSuccess: (ResponseModel<TicketChangeData>) -> Unit = {},
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.get<BaseResponse<ResponseModel<TicketChangeData>>>(BaseUrl.stsTicketRed)
            .params(
                getParams(
                    "type" to type,
                    "id" to goodsId,
                    "method" to method,
                    "beginDate" to beginDate,
                    "endDate" to endDate,
                    "pageStart" to page * 20,
                    "pageSize" to 20
                )
            )
            .converter(object : JsonConvert<BaseResponse<ResponseModel<TicketChangeData>>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data }
            .subscribeByFinally(
                event = this,
                onSuccess = onSuccess,
                onFinally = onFinally
            )
    )

    /**
     * 商品统计一级列表
     */
    fun goodList(
        page: Int,
        beginDate: String,
        endDate: String,
        onSuccess: (ResponseModel<HomeContent>) -> Unit = {},
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.get<BaseResponse<ResponseModel<HomeContent>>>(BaseUrl.stsGoodsSum)
            .params(
                getParams(
                    "beginDate" to beginDate,
                    "endDate" to endDate,
                    "pageStart" to page * 20,
                    "pageSize" to 20
                )
            )
            .converter(object : JsonConvert<BaseResponse<ResponseModel<HomeContent>>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map { it.data }
            .subscribeByFinally(
                event = this,
                onSuccess = onSuccess,
                onFinally = onFinally
            )
    )

    /**
     * 商品统计订单列表
     */
    fun goodRecord(
        page: Int,
        product: String,
        beginDate: String,
        endDate: String,
        onSuccess: (Int, ArrayList<Any>) -> Unit = { _, _ -> },
        onFinally: () -> Unit = {}
    ) = mDisposables.add(
        OkGo.get<BaseResponse<OrderModel>>(BaseUrl.stsOrderDet)
            .params(
                getParams(
                    "productId" to product,
                    "beginDate" to beginDate,
                    "endDate" to endDate,
                    "pageStart" to page * 20,
                    "pageSize" to 20
                )
            )
            .converter(object : JacksonConvert<BaseResponse<OrderModel>>() {})
            .adapt(FlowableBody())
            .compose(applyFlowableSchedulers())
            .map {
                ArrayList<Any>().apply {
                    it.data.data.forEach { item ->
                        // 添加头部
                        add(OrderHeader().apply {
                            orderSN = item.sn
                            hint = "下单时间："
                            time = item.createDate.getTimeString()
                            status_hint = ""
                        })

                        // 添加商品
                        addItems(
                            item.orderItems.onEach {
                                it.orderSN = item.sn
                                it.consignee = item.consignee.orEmpty()
                                it.phone = item.phone.orEmpty()
                            }
                        )

                        // 添加底部
                        add(OrderFooter().apply {
                            orderSN = item.sn
                            total_num = item.quantity
                            amount = item.amountPaid.orEmpty()
                        })
                    }

                    add(it.data.recordsTotal)
                }
            }
            .subscribeByFinally(
                event = this,
                onSuccess = { onSuccess(it.removeLast() as Int, it) },
                onFinally = { onFinally() }
            )
    )

}